﻿using System;
using System.Data;
using System.Collections.Generic;
using LTP.Common;
using TuKu.Model;
namespace TuKu.BLL
{
    /// <summary>
    /// 业务逻辑类urlcate 的摘要说明。
    /// </summary>
    public class urlcate
    {
        private readonly TuKu.DAL.urlcate dal = new TuKu.DAL.urlcate();
        public urlcate()
        { }
        #region  成员方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(TuKu.Model.urlcate model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(TuKu.Model.urlcate model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int id)
        {

            dal.Delete(id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TuKu.Model.urlcate GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中。
        /// </summary>
        public TuKu.Model.urlcate GetModelByCache(int id)
        {

            string CacheKey = "urlcateModel-" + id ;
            object objModel = LTP.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(id);
                    if (objModel != null)
                    {
                        int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
                        LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (TuKu.Model.urlcate)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<TuKu.Model.urlcate> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List<TuKu.Model.urlcate> modelList = new List<TuKu.Model.urlcate>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                TuKu.Model.urlcate model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new TuKu.Model.urlcate();
                    if (ds.Tables[0].Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(ds.Tables[0].Rows[n]["id"].ToString());
                    }
                    model.catename = ds.Tables[0].Rows[n]["catename"].ToString();
                    model.enname = ds.Tables[0].Rows[n]["enname"].ToString();
                    if (ds.Tables[0].Rows[n]["sortid"].ToString() != "")
                    {
                        model.sortid = int.Parse(ds.Tables[0].Rows[n]["sortid"].ToString());
                    }
                    if (ds.Tables[0].Rows[n]["addtime"].ToString() != "")
                    {
                        model.addtime = DateTime.Parse(ds.Tables[0].Rows[n]["addtime"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

